-
Notifications
You must be signed in to change notification settings - Fork 744
/
AuthCookieController.cs
78 lines (66 loc) · 2.54 KB
/
AuthCookieController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information
namespace DotNetNuke.Security.Cookies
{
using System;
using System.Web.Caching;
using System.Web.Security;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Data;
using DotNetNuke.Framework;
public class AuthCookieController : ServiceLocator<IAuthCookieController, AuthCookieController>, IAuthCookieController
{
private readonly DataProvider dataProvider = DataProvider.Instance();
/// <inheritdoc/>
public void Update(string cookieValue, DateTime utcExpiry, int userId)
{
if (string.IsNullOrEmpty(cookieValue))
{
return;
}
DataCache.ClearCache(GetKey(cookieValue));
this.dataProvider.UpdateAuthCookie(cookieValue, utcExpiry, userId);
}
/// <inheritdoc/>
public PersistedAuthCookie Find(string cookieValue)
{
if (string.IsNullOrEmpty(cookieValue))
{
return null;
}
return CBO.Instance.GetCachedObject<PersistedAuthCookie>(
new CacheItemArgs(
GetKey(cookieValue),
(int)FormsAuthentication.Timeout.TotalMinutes,
CacheItemPriority.AboveNormal),
_ => CBO.Instance.FillObject<PersistedAuthCookie>(this.dataProvider.FindAuthCookie(cookieValue)),
false);
}
/// <inheritdoc/>
public void DeleteByValue(string cookieValue)
{
if (string.IsNullOrEmpty(cookieValue))
{
return;
}
// keep in cache so hacking tries don't hit the database; it will expire automatically
// DataCache.ClearCache(GetKey(cookieValue));
this.dataProvider.DeleteAuthCookie(cookieValue);
}
/// <inheritdoc/>
public void DeleteExpired(DateTime utcExpiredBefore)
{
this.dataProvider.DeleteExpiredAuthCookies(utcExpiredBefore);
}
/// <inheritdoc/>
protected override Func<IAuthCookieController> GetFactory()
{
return () => new AuthCookieController();
}
private static string GetKey(string cookieValue)
{
return $"AuthCookie:{cookieValue}";
}
}
}